package actions;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class DownloadAction extends org.apache.struts.actions.DispatchAction 
{    
    public DownloadAction() 
    {
    
    }
    
    public ActionForward Download(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
    {
    	ActionForward forward= new ActionForward();
    	java.io.FileInputStream fileInputStream=null;
    	String fileName="backup.dmp";
    	String filePath="d:\\";
    	response.setContentType("APPLICATION/OCTET-STREAM");
    	response.setHeader("Content-Disposition","attachment;fileName=\""+fileName+"\"");
    	try
    	{
    		fileInputStream=new FileInputStream(filePath+fileName);
    		PrintWriter out=response.getWriter();
    		int i;
    		while((i = fileInputStream.read())!= -1)
    		{
    			out.write(i);
    		}
    		fileInputStream.close();
    	}
    	catch(Exception e)
    	{
    		
    	}
    	return null;
    }
    
    public ActionForward Back(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
    {
    	ActionForward forward= new ActionForward();
    	forward=mapping.findForward("backtohomepage");
    	return forward;
    }
    
    
    public ActionForward BackToHome(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
    {
    	ActionForward forward= new ActionForward();
    	forward=mapping.findForward("backtohomepage");
    	return forward;
    }

}